package com.tomcat.myapplication.http;

import com.tomcat.myapplication.bean.DataBean;

import okhttp3.RequestBody;
import okhttp3.internal.Internal;
import rx.Observable;
import rx.Subscriber;

public class HttpFactory<T> extends HttpRetrofit {
    private volatile static HttpFactory mHttpFactory = null;

    /**
     * 懒汉线程安全单例模式
     */
    public static HttpFactory getInstance() {

        //先检查实例是否存在，如果不存在才进入下面的同步块
        if (Internal.instance == null) {
            //同步块，线程安全的创建实例
            synchronized (HttpFactory.class) {
                //再次检查实例是否存在，如果不存在才真的创建实例
                if (Internal.instance == null) {
                    mHttpFactory = new HttpFactory();
                }
            }
        }
        return mHttpFactory;
    }
    public void getDriverfree(Subscriber<DataBean> subscriber, RequestBody requestBody){
        Observable<DataBean> observable = getService().getDriverfree(requestBody)
                .map(new HttpCodeFuncData<DataBean>());
        toSubscribeMainThread(observable,subscriber);
    }
}
